from zope.interface import implements

from twisted.internet import protocol, reactor, defer, ssl
from twisted.protocols import basic

from pyhsrv import interfaces, errors

class DBSyncProtocol(basic.LineReceiver):

    def __init__(self):
        pass

    def writeValue(self, value):
        self.transport.write(value + "\r\n")

    def lineReceived(self, msg):
        d = self.factory.parseMsg(msg)
        d.addErrback(errors.catchError)
        d.addCallback(self.writeValue)

    def connectionMade(self):
        d = self.factory.newConnection(self, selt.transport.getPeer().host)
        d.addErrback(errors.catchError)
        d.addCallback(self.writeValue)
